import { defineConfig } from 'vite'
import { resolve } from 'path'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite';
import IconsResolver from 'unplugin-icons/resolver';

import { VantResolver } from '@vant/auto-import-resolver';

export default defineConfig({
  base: './',
  server: {
    open: true,
    port: 3000,
    proxy: {
      '/dev-api': {
        // target: 'http://192.168.1.115:9098', // 洪明
        // target: 'http://192.168.4.242:8080', // 洪明
        // target: `http://192.168.4.160:8080`, // 李堃
        target: 'http://xbtstest.westts.cn/prod-api', // 线上
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/dev-api/, '')
      }
    }
  },
  build: {
    outDir: 'dist',
    // assetsInlineLimit: 4096,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes('node_modules')) {
            return 'vendor'
          }
        }
      }
    },
    terserOptions: {
      compress: {
        drop_console: true, // 移除 console
        drop_debugger: true // 移除 debugger
      }
    }
  },
  resolve: {
    alias: {
      "@": resolve(__dirname, './src')
    },
  },
  plugins: [
    vue(),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        'vuex'
      ],
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          prefix: 'Icon', // 自定义图标前缀，可选
        }),
        VantResolver()
      ],
      dts: 'src/auto-imports.d.ts', // 自动生成 TypeScript 声明文件
    }),
    Components({
      dirs: ['src/components'],
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          enabledCollections: ['ep'], // 指定自动导入的图标集合Element Plus图标
        }),
        VantResolver(),
      ],
    }),
    Icons({
      autoInstall: true, // 自动安装图标
    }),
  ],
})
